package exam.test17;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description: 
 * User: Endstart
 * Date: 2020-12-17
 * Time: 8:40
 */
public class PassphraseLock extends Lock {

    private Set<String> passphrases;

    public PassphraseLock(Owner owner, String masterPassphrase, Set<String> passphrases) {
        super(owner, masterPassphrase);
        this.passphrases = passphrases;
    }

    public boolean setPassphrases(Owner owner, Set<String> passphrases) {
        if (!this.owner.equals(owner)) {
            return false;
        }
        this.passphrases = passphrases;
        return true;
    }

    public boolean unlock(String passphraseOne, String passphraseTwo, String passphraseThree) {
        if (lock) {
            Set<String> set = new HashSet<>();
            set.add(passphraseOne);
            set.add(passphraseTwo);
            set.add(passphraseThree);
            if (set.size() != 3) {
                return false;
            }
            if (passphrases.contains(passphraseOne)
                    && passphrases.contains(passphraseTwo)
                    && passphrases.contains(passphraseThree)) {
                lock = false;
            }
        }
        return lock;
    }

}
